<template>
	<view>
		<view class="header">
			<image src="../../../static/icons/arrl.png" mode="" @tap="back"></image>
			<text>乐居</text>
		</view>
		<view class="list">
			<view class="item" v-for="el in list" :key="el.id" @tap="localInfo(el)">
				<view class="left">
					<view>
						<text>{{el.name}}</text>
						<text class="mo" v-if="el.defaultStatus">默认</text>
					</view>
					<view>{{el.phoneNumber}}</view>
				</view>
				<view class="right" @tap="jumpAddSite(el.id,el.defaultStatus,el)">
					<view>
						<image src="../../../static/icons/edit.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="addSite" @tap="jumpAddSite2">新增地址</view>
	</view>
</template>

<script>
	import { findAllAddress } from "../../../api/user/index.js"
	export default {
		data() {
			return {
				list:[],
				isShow:false
			};
		},
		methods:{
			init() {
				findAllAddress().then(res=>{
					console.log(res)
					this.list = res.data.items
				})
			},
			back() {
				uni.switchTab({
					url:"/pages/user/user"
				})
			},
			jumpAddSite(id,status,ele) {
				ele = JSON.stringify(ele)
				uni.navigateTo({
					url:`/pages/user/site/addSite/addSite?id=${id}&status=${status}&item=${ele}`
				})
			},
			jumpAddSite2() {
				uni.navigateTo({
					url:"/pages/user/site/addSite/addSite"
				})
			},
			localInfo(item) {
				console.log(item)
				if (this.isShow) {
					uni.setStorageSync("siteInfo",item)
					uni.navigateBack({
						delta:1
					})
				}
			}
		},
		onLoad(options) {
			this.init()
			if (options.isShow != undefined) {
				this.isShow = options.isShow
			}
			
		}
	}
</script>

<style lang="scss" scoped>
.header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #354e44;
	height: 60rpx;
	padding: 14rpx 6rpx;
	image {
		position: absolute;
		left: 4rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
	}
	text {
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: bolder;
	}
}
.list {
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 94%;
		height: 90rpx;
		padding: 20rpx 0;
		margin: 0 auto;
		border-bottom: 2rpx solid #ccc;
		.left {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			height: 90rpx;
			margin-left: 30rpx;
			>view {
				&:first-child {
					display: flex;
					align-items: center;
					font-size: 28rpx;
					color: #000000;
						.mo {
							height: 32rpx;
							font-size: 24rpx;
							color: #FFFFFF;
							padding: 0 18rpx;
							margin-left: 20rpx;
							background-color: #354e44;
							border-radius: 8rpx;
						}
				}
				&:last-child {
					font-size: 24rpx;
					color: #999;
				}
			}
		}
		.right {
			width: 40rpx;
			height: 40rpx;
			padding: 10rpx 20rpx;
			border-left: 1px solid #aaa;
			image {
				display: block;
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
}
.addSite {
	position: fixed;
	bottom: 20rpx;
	left: 50%;
	transform: translateX(-50%);
	width: 70%;
	height: 80rpx;
	background-color: #354e44;
	border-radius: 80rpx;
	box-shadow: 0px 2px 5px rgba(0,0,0,.4);
	font-size: 30rpx;
	color: #FFFFFF;
	text-align: center;
	line-height: 80rpx;
}
</style>
